﻿using CommunityToolkit.Mvvm.DependencyInjection;
using Kang.Monitor.Wpf.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Kang.Monitor.Wpf.Views.ReportViews
{
    /// <summary>
    /// StressView.xaml 的交互逻辑
    /// </summary>
    public partial class StressView : UserControl
    {
        public StressView()
        {
            InitializeComponent(); 
        }
        /// <summary>
        /// 排序功能
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lvList_Click_1(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource is GridViewColumnHeader)
            {
                //获得点击的列
                GridViewColumn clickedColumn = (e.OriginalSource as GridViewColumnHeader).Column;
                if (clickedColumn != null)

                {
                    //Get binding property of clicked column

                    string bindingProperty = (clickedColumn.DisplayMemberBinding as Binding).Path.Path;
                    //获得listview项是如何排序的
                    SortDescriptionCollection sdc = this.lvList.Items.SortDescriptions;

                    //按升序进行排序
                    ListSortDirection sortDirection = ListSortDirection.Ascending;
                    if (sdc.Count > 0)
                    {
                        SortDescription sd = sdc[0];
                        sortDirection = (ListSortDirection)((((int)sd.Direction) + 1) % 2);
                        sdc.Clear();
                    }
                    sdc.Add(new SortDescription(bindingProperty, sortDirection));
                }
            }
        }

        }
    }
